import Utils from "../common/Util";
import { ScoreObjPool } from "../common/ScoreObjPool";

const { ccclass, property } = cc._decorator;

@ccclass 
export default class ScoreCom extends cc.Component {
    private bIsHit: boolean;
    private bIsMoving: boolean;
    private bIsCanDrag: boolean;
    private orginPos: cc.Vec2;

    init() {
        this.node.x = 0;
        this.node.y = 0;

        //默认先缩放至最小(为了做放大的动画)
        this.node.active = true;
        this.node.opacity = 255;
        this.node.setScale(0.1);
    }

    showScore(pos, score, callback = null) {
        var self = this;

        pos.y += 40;

        this.node.setPosition(pos);
        Utils.SetNodeText(this.node, score);

        //先放大到正常大小
        var scaleAction = cc.scaleTo(0.3, 0.5, 0.5);
        this.node.scale = 0.5;
        //然后延时
        var delayAction = cc.delayTime(0.3);
        //最后上移和渐隐
        var moveAction = cc.moveBy(0.5, 0, 30);
        var fadeOutAction = cc.fadeOut(0.5);
        var spawn = cc.spawn(moveAction, fadeOutAction);
        //回调函数
        var func = cc.callFunc(function () {
            //回收
            ScoreObjPool.PutScoreObj(self.node);

            if (callback) {
                callback();
            }
        });

        var sequence = cc.sequence(delayAction, spawn, func);

        this.node.runAction(sequence);
    }
}